package com.gadgets.busi.dataanalysis.registry;

import com.gadgets.busi.bm02.common.GadgetsBm02Constant;
import com.gadgets.busi.bm02.service.IMaterialAnalysisService;
import com.gadgets.busi.dataanalysis.registry.task.DataAnaylsisMainRunnable;
import com.gadgets.framework.common.util.ThreadTaskUtil;
import com.gadgets.framework.start.AbstractInitLoaderProcess;
import com.gadgets.framework.thread.basic.ThreadPoolConfiguration;
import com.gadgets.framework.thread.pool.GadgetsThreadPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-12-01
 *
 */
@Component
public class Bm02DataAnalysisExcutor extends AbstractInitLoaderProcess {

    @Autowired
    @Qualifier(value = "dataAnalysisServiceImpl")
    private IMaterialAnalysisService materialAnalysisService;

    public Bm02DataAnalysisExcutor() {
        super(Integer.MIN_VALUE+502);
    }

    /**
     * 初始化执行方法
     *
     * @param context Spring上下文
     */
    @Override
    public void initLoad(ApplicationContext context) {
        // 注册bm02-da线程池
        ThreadPoolConfiguration configuration = new ThreadPoolConfiguration();
        configuration.setMinThread(6);
        configuration.setCurrentThread(6);
        configuration.setMaxThread(10);
        configuration.setFlowLimitSize(500);
        configuration.setModuelNo(GadgetsBm02Constant.DA_MODUEL_NO);
        configuration.setLevelUpThreshold(1.0);
        configuration.setLevelDownThreshold(0.0);
        GadgetsThreadPool.registryModuel(configuration);
        DataAnaylsisMainRunnable anaylsisMainRunnable = new DataAnaylsisMainRunnable();
        // 提交数据分析任务
        anaylsisMainRunnable.setAnalysisService(materialAnalysisService);
        anaylsisMainRunnable.setModuelNo(GadgetsBm02Constant.DA_MODUEL_NO);
        ThreadTaskUtil.submit(anaylsisMainRunnable);
    }

}
